package com.matthewmadson.util.search;

import java.io.IOException;

import org.json.JSONException;

import com.google.common.collect.Lists;
import com.matthewmadson.util.search.yahooboss.YBWebQuery;
import com.matthewmadson.util.search.yahooboss.YBWebQueryMetadata;
import com.matthewmadson.util.search.yahooboss.YBWebQueryResult;
import com.matthewmadson.util.search.yahooboss.YBWebQueryResultSet;

public class YBWebQueryExample
{
	private static final String yahooApplicationID = "iyuFzVrV34Hgc10f_01t9I.c.tUkwfahnRwCsAaM1YkvXLFoInGTCMkZOzrYNwatUpKV";
	
	public static void main(String...args) 
	throws IOException, JSONException
	{
		YBWebQuery yq = Query.newYahooBossWebQuery(yahooApplicationID);
		yq.addSearchTerm("james");
		yq.addSearchTerms(Lists.newArrayList("bond", "007"));
		yq.addExcludedSearchTerm("craig");
		yq.addExcludedSearchTerms(Lists.newArrayList("solace", "sean"));
		yq.addDomain("wikipedia.org");
		yq.addDomains(Lists.newArrayList("ucsd.edu", "imdb.com"));
		yq.addExcludedDomain("yahoo.com");
		yq.addExcludedDomains(Lists.newArrayList("google.com", "cse.ucsd.edu"));
		yq.setStart(10);
		yq.setResultsPerPage(50);
		yq.setLocale("en", "us");
		yq.enablePornFilter(false);
		yq.enableHateFilter(false);
		yq.addDocumentType("html");
		yq.addDocumentTypes(Lists.newArrayList("text", "pdf"));
		yq.addExcludedDocumentType("msoffice");		
		
		YBWebQueryResultSet results = yq.getResultSet();
		YBWebQueryMetadata metadata = results.getMetadata();
		System.out.println(metadata.getDeepHits());
		System.out.println(metadata.getTotalHits());
		System.out.println(metadata.getStart());
		int i = 0;
		for(YBWebQueryResult result : results)
		{
			if(i == 100)
				break;
			System.out.println("---------------------------["+result.getOffset()+"]------------------------------");
			System.out.println(result.getAbstract());
			System.out.println(result.getClickURL());
			System.out.println(result.getDate());
			System.out.println(result.getDispURL());
			System.out.println(result.getSize());
			System.out.println(result.getTitle());
			System.out.println(result.getURL());
			System.out.println("---------------------------------------------------------");
			i++;
		}
	}
}
